<?php

namespace App\Api\Controllers;

use App\Api\Models\SystemConfigModel;
use App\Http\Controllers\Api\BaseController;
use Illuminate\Http\Request;

class SystemConfigController extends BaseController
{
    //
    public function set(Request $request)
    {
        if(in_array($request->val, [0, 1])) {
            SystemConfigModel::where('key_value', 'switch')->update(['value' => $request->val]);
            return $this->success();
        }
        else {
            return $this->fail('', '参数不合法');
        }
    }

    public function get()
    {
        $result = SystemConfigModel::where('key_value', 'switch')->first();
        return $this->success(
            $result['value']
        );
    }
}
